//
//  JMProjectManager.m
//  JMBaseProject
//
//  Created by liuny on 2018/7/14.
//  Copyright © 2018年 liuny. All rights reserved.
//

#import "JMProjectManager.h"
#import "JMFileManagerHelper.h"


@interface JMProjectManager()
@end


@implementation JMProjectManager
singleton_implementation(JMProjectManager)
@synthesize loginUser=_loginUser;
@synthesize appConfig=_appConfig;

#pragma mark - 登录用户缓存
-(void)setLoginUser:(JMLoginUserModel *)loginUser{
    if(loginUser){
        _loginUser = loginUser;
        [_loginUser save];
    }else{
        [_loginUser clear];
        _loginUser = loginUser;
    }
}
+(BOOL)isLogin{
    if(JMProjectManager.sharedJMProjectManager.loginUser.token.length==0){
        return NO;
    }else{
        return YES;
    }
}
-(JMLoginUserModel *)loginUser{
    if(_loginUser == nil){
        if([JMFileManagerHelper isExistsAtPath:kLoginUserSavePath]){
            _loginUser = [NSKeyedUnarchiver unarchiveObjectWithFile:kLoginUserSavePath];
        }else{
            _loginUser = [[JMLoginUserModel alloc]init];
        }
    }
    return _loginUser;
}
-(JMAppConfig *)appConfig{
    if(!_appConfig){
        _appConfig = [[JMAppConfig alloc]init];
    }
    return _appConfig;
}
@end











@implementation JMAppConfig
MJCodingImplementation
-(NSString *)adid{
    if (!_adid) {
        NSString *adId = [Adjust adid];
        NSString *idfa = [Adjust idfa];
        if (adId) {
            _adid = adId;
        }else if(idfa.length){
            _adid = idfa;
        }else{
            _adid = @"";
        }
    }
    return _adid;
}
-(NSString *)uuidString{
    if (!_uuidString) {
        _uuidString = [[NSUUID UUID] UUIDString];
    }
    return _uuidString;
}


@end
